import 'package:flutter/material.dart';

class MsgList extends StatelessWidget{
  String title = '';
  String src = '';
  var cImg = '';
  String name = '';
  String tagName = '';
  String content = '';
  var num = 0;
  bool isImg;
  List<String> taglist = [];


  MsgList(this.title,this.src,this.name,this.taglist,this.content,this.isImg,[this.cImg]){

    if(taglist != []){
      for (var i = 0; i < taglist.length; i++) {
        tagName += '、'+ taglist[i];
      }
     tagName =  tagName.substring(1);
    }
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return GestureDetector(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(title,
            style: TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 18
            ),
            maxLines: 2,
            overflow: TextOverflow.ellipsis,

          ),
          SizedBox(
            height: 5.0,
          ),
          Row(
            children: <Widget>[
              Expanded(
                  flex: 8,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          ClipOval(
                            child: Image.network(
                              src == ''?'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1576832202&di=e98bdda757ba0a226fa7b17a704396a6&imgtype=jpg&er=1&src=http%3A%2F%2Fimage.biaobaiju.com%2Fuploads%2F20180801%2F21%2F1533130354-tcjsiIBbEW.png':src,
                              width: 20,
                              height: 20,
                              fit: BoxFit.cover,
                            ) ,
                          ),
                          SizedBox(
                            width: 5.0,
                          ),
                          Text(name,
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: 12
                            ),
                          ),
                          SizedBox(
                            width: 10.0,
                          ),
                          Expanded(
                            child: Text(tagName,
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Colors.grey
                              ),
                              overflow: TextOverflow.ellipsis,
                            ),
                          )
                        ],
                      ),
                      Container(
                        margin: EdgeInsetsDirectional.fromSTEB(0,5,0,5),
                        child: Text(content,
                          style: TextStyle(
                              fontSize: 14
                          ),
                          maxLines: 3,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      Row(
                        children: <Widget>[
                          Text('$num人预览',
                            style: TextStyle(
                                fontSize: 12
                            ),
                          )
                        ],
                      )
                    ],
                  )
              ),
              SizedBox(
                width: 10.0,
              ),
              _isImg()
            ],
          )
        ],
      ),
      onTap:(){
        Navigator.pushNamed(context, '/detail');
      } ,
    );

  }

  Widget _isImg(){
    var widget_i;
    if(this.isImg){
      widget_i = Expanded(
        flex: 3,
        child: Image.network(cImg,
        width: 100,
        height: 60,
        fit: BoxFit.cover,
      ));
    }else{
      widget_i = Expanded(
          flex: 0,
        child: SizedBox(
        width: 0,
        height: 0,
      ));
    }
    return widget_i;

  }
}